﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Mail;

namespace MotivLogger.LogMethods
{
    class MailLog : ILogMethod
    {
        private ISetting LoggerSettings;
        public void Log(MotivLogger.LogLevels Level, string body, string Actor)
        {

            LoggerSettings = Settings.getSetting("adreses");
            string Adress = this.LoggerSettings.GetData(Level.ToString());
            if (Adress != null)
            {
                MailMessage Message = new MailMessage();
                SmtpClient Smtp = new SmtpClient("inbox.ycc.ru");

                string Sender = Settings.getSetting("logger").child["logmethods"].child["maillog"].GetStr("sender", "it_madcrank@ycc.ru");
                Smtp.EnableSsl = Settings.getSetting("logger").child["logmethods"].child["maillog"].GetBool("sender", false);
                Message.Subject = "Error " + Level.ToString() + " in " + Actor.ToString();
                Message.Body = body;
                Message.From = new System.Net.Mail.MailAddress(Sender);
                foreach (string adress in Adress.Split('|'))
                {
                    Message.To.Add(new MailAddress(adress));
                }
                Smtp.UseDefaultCredentials = true;
               // Smtp.EnableSsl = true;
                Smtp.Send(Message);
            }
        }
        public void Stop() { ;}
    }
}
